/**
 * 储存了所有已注册的异步处理方法
 */
export const flows = {};

/**
 * 处理异步flow的action请求
 *
 * @param {object[]} models 所有已注册的models数组
 */
export default models => {
  models.forEach(model => {
    const { namespace, flows: originFlows } = model;
    if (namespace && originFlows) {
      for (let key in originFlows) {
        const flow = originFlows[key];

        if (flows[namespace] && flows[namespace][key])
          throw new Error(
            `has same flow function: ${key} in namespace: [${namespace}]`
          );

        flows[namespace] = Object.assign({}, flows[namespace], {
          [key]: flow
        });
      }
    }
  });
};
